package com.hdax.search.controller;


import com.hdax.common.exception.BizCodeEnume;
import com.hdax.common.to.es.SkuEsModel;
import com.hdax.common.utils.R;
import com.hdax.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;


@RequestMapping("/saerch/save")
@RestController
@Slf4j
public class ElasticSearchController {

    @Autowired
    private ProductSaveService productSaveService;




    /**
     * 商品上架
     * @param skuEsModels
     * @return
     */
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        boolean b=false;
        try {
            b=productSaveService.productSaveUp(skuEsModels);
        } catch (IOException e) {
            log.error("ElasticSearch上架错误",e);
            return R.error(BizCodeEnume.PROEUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PROEUCT_UP_EXCEPTION.getMsg());
        }

        if(b){
            return R.ok();
        }else{
           return R.error(BizCodeEnume.PROEUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PROEUCT_UP_EXCEPTION.getMsg());
        }
    }
}
